<template>
  <div>
    <el-row style="margin: 10px">
      <el-col :span="4">
        <el-input v-model="searchName" placeholder="通过举报用户名搜索" clearable maxlength="15" />
      </el-col>
      <el-col :span="4" style="margin-left: 20px">
        <el-input v-model="searchReason" placeholder="通过举报理由搜索" clearable maxlength="20" />
      </el-col>
      <el-col :span="3" style="margin-left: 20px">
        <el-button type="primary" @click="handleSearch">搜索</el-button>
      </el-col>
    </el-row>
    <el-table :data="userData" style="width: 100%">
      <el-table-column label="举报人" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column label="举报房源" align="center">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>标题: {{ scope.row.houseTitle || '未填写' }}</p>
            <p>简介: {{ scope.row.houseIntroduce || '未填写' }}</p>
            <p>详细地址: {{ scope.row.houseDistrict + scope.row.houseAddress || '未填写' }}</p>
            <p>房间格局: {{ scope.row.houseRoom + "房" + scope.row.houseParlor + "厅" + scope.row.houseLavatory + "卫" || '未填写' }}</p>
            <p v-if="scope.row.type === 0">租金: {{ scope.row.housePrice || '未填写' }}元/每月</p>
            <p v-if="scope.row.type === 1">售价: {{ scope.row.housePrice || '未填写' }}元</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.houseTitle }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="举报理由" align="center">
        <template slot-scope="scope">
          <span v-if="!scope.row.reason">无</span>
          <el-popover v-else trigger="hover" placement="top">
            <p>{{ scope.row.reason }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.reason.length>10?scope.row.reason.substring(0,7)+'...':scope.row.reason }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="是否处理" width="180" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.isHandle === true" style="color: #67C23A">已处理</span>
          <span v-if="scope.row.isHandle === false" style="color: #F78989">未处理</span>
        </template>
      </el-table-column>
      <el-table-column label="举报时间" width="240" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px"><el-date-picker type="datetime" :value="scope.row.createTime" readonly /></span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="getDetail(scope.row)">查看</el-button>
          <el-button v-if="scope.row.isBan === false" size="mini" type="text" style="color: #F6416C" @click="ban(scope.$index, scope.row)">下架</el-button>
          <el-button v-else-if="scope.row.isBan === true" size="mini" type="text" @click="cancelBan(scope.$index, scope.row)">上架</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="12" :offset="14" style="margin-top: 20px">
      <el-pagination
        background
        layout="prev, pager, next, jumper, sizes"
        :current-page="page.currentPage"
        :total="page.total"
        :pager-count="5"
        :page-size="page.pageSize"
        :page-sizes="page.pageSizes"
        @current-change="pageChange"
        @size-change="sizeChange"
      />
    </el-col>

    <report-detail ref="reportDetail" style="" :handle-status="handleStatus" />

  </div>
</template>

<script>

import { getReportList, getReportDetail } from '@/api/report'
import reportDetail from '@/views/report/reportDetail'

export default {
  filters: {},
  components: { reportDetail },
  data() {
    return {
      userData: [],
      searchName: '',
      searchReason: '',
      page: {
        pageSize: 5,
        pageSizes: [5, 10, 20, 40, 80],
        totalPage: 1,
        total: 0,
        currentPage: 1
      },
      handleStatus: false,
      dialogVisible: false
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getReportList({
        page: this.page.currentPage,
        limit: this.page.pageSize,
        searchName: this.searchName,
        searchReason: this.searchReason
      }).then((res) => {
        if (JSON.parse(res.data.list).length <= 0) {
          this.$message({
            message: '获取不到房源信息~',
            type: 'warning'
          })
        }
        this.userData = JSON.parse(res.data.list)
        this.page.total = res.data.total
        this.page.totalPage = res.data.totalPage
      })
    },
    handleSearch() {
      this.page.currentPage = 1
      this.getList()
    },
    // 查看详情
    getDetail(report) {
      getReportDetail({
        id: report.id
      }).then(res => {
        console.log(res)
        this.$refs.reportDetail.getReportDetail(res.data)
        this.$refs.reportDetail.dialogVisible = true
      })
      this.getList()
    },
    handleEdit(index, row) {
      console.log(index, row)
    },
    pageChange(page) {
      this.page.currentPage = page
      this.getList()
    },
    sizeChange(size) {
      this.page.pageSize = size
      this.getList()
    }
  }
}
</script>
